import {addOneSupplierAPI, getSupplierInfoAPI} from "@/apis/supplier.jsx";
import {useEffect, useState} from "react";
import {message} from "antd";
import {useNavigate} from "react-router-dom";

 function useSaveOneSupplier() {
    return async (data)=>{
        return await addOneSupplierAPI(data).then()
    }
}

const useGetSupplierById=(id)=>{

    const navigator=useNavigate()
 const [supplier,setSupplier]=useState({})
    useEffect(() => {
        const getOneSupplierById=async ()=>{
         const res=await getSupplierInfoAPI(id)
            if(res.code===200){
                setSupplier(res.data)
            }
            else if(res.code===500){
                message.error(res.msg)
                navigator('/backgroundManage/supplier')
            }
        }
        getOneSupplierById().then()
    },[])
    return supplier
}



export {
     useSaveOneSupplier,useGetSupplierById
}